using System;
using System.Data.Entity.ModelConfiguration;
using System.Data.Common;
using System.Data.Entity;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using MAPDavy.Entities;

namespace MAPDavy.Repository.Mapping
{
	public class MatriculaMap : EntityTypeConfiguration<Matricula>
	{
		public MatriculaMap()
		{
			// Primary Key
			this.HasKey(t => t.Id);

			// Properties
			this.Property(t => t.StudentId)
				.IsRequired()
				.IsFixedLength()
				.HasMaxLength(6);
				
			this.Property(t => t.Anio)
				.IsRequired()
				.IsFixedLength()
				.HasMaxLength(4);
				
			// Table & Column Mappings
			this.ToTable("Matricula");
			this.Property(t => t.Id).HasColumnName("Id");
			this.Property(t => t.StudentId).HasColumnName("StudentId");
			this.Property(t => t.SeccionId).HasColumnName("SeccionId");
			this.Property(t => t.DateMatricula).HasColumnName("DateMatricula");
			this.Property(t => t.Activo).HasColumnName("Activo");
			this.Property(t => t.Anio).HasColumnName("Anio");
            this.Property(t => t.FileNameReportCard).HasColumnName("FileNameReportCard");

			// Relationships
			this.HasOptional(t => t.SeccionTutor)
				.WithMany(t => t.Matriculas)
				.HasForeignKey(d => new { d.SeccionId, d.Anio });
				
			this.HasRequired(t => t.Student)
				.WithMany(t => t.Matriculas)
				.HasForeignKey(d => d.StudentId);
				
		}
	}
}

